<?php //$model = Products::model()->findAll();?>
<!-- BEGIN PAGE CONTAINER-->
<div class="container-fluid">
    <!-- BEGIN PAGE HEADER-->
    <div class="row-fluid">
        <div class="span12">
            <!-- BEGIN PAGE TITLE & BREADCRUMB-->
            <h3 class="page-title">
                Quản lý sản phẩm
            </h3>
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home"></i>
                    <a href="index.html">Trang chủ</a>
                    <i class="icon-angle-right"></i>
                </li>
                <li>
                    <a href="#">Sản phẩm</a>
                    <i class="icon-angle-right"></i>
                </li>
                <li><a href="#">Danh mục sản phẩm</a></li>
            </ul>
            <!-- END PAGE TITLE & BREADCRUMB-->
        </div>
    </div>
    <!-- END PAGE HEADER-->
    <!-- BEGIN PAGE CONTENT-->
    <div class="row-fluid">
        <div class="span12">
            <!-- BEGIN EXAMPLE TABLE PORTLET-->
            <div class="portlet box light-grey">
                <div class="portlet-title">
                    <h4><i class="icon-th-list"></i>Danh mục sản phẩm</h4>

                    <div class="tools">
                        <a href="javascript:;" class="collapse"></a>
                    </div>
                </div>
                <div class="portlet-body">
                    <div class="clearfix">
                        <div class="btn-group" style="float:left">
                            <a href="/admin/products/create">
	                            <button id="sample_editable_1_new" class="btn green">
	                                Thêm mới <i class="icon-plus"></i>
	                            </button>
                            </a>
                        </div>
                        <div class="btn-group pull-right">
                            <!--
                            <button class="btn red" type="button">
                                Xóa <i class="icon-trash"></i>
                            </button>
                            -->
                        </div>
                    </div>
                    <div class="clearfix">
                        <div class="btn-group" style="float:left">
                            <form name="search-product" method="POST" action="" style="margin:0">
                            <div class="input-group">
                                <input type="text" name="keyword" value="<?php echo $keyword;?>" class="m-wrap medium">
                                <span class="input-group-btn">
                                    <button class="btn btn-default" type="submit">Search</button>
                                </span>
                            </div>
                            </form>
                        </div>
                        
                        <div class="btn-group pull-right">
                            <form name="filter-product" method="GET" action="/admin/products/admin" style="margin:0">
                                <select name="filter" onChange="this.form.submit();">
                                	<option <?php echo ($filter == 'all')?'selected':'';?> value="all">-- Choose --</option>
                                	<option <?php echo ($filter == 'home')?'selected':'';?> value="home">Product home</option>
                                	<option <?php echo ($filter == 'new')?'selected':'';?> value="new">Product new</option>
                                	<option <?php echo ($filter == 'special')?'selected':'';?> value="special">Product special</option>
                                </select>
                             </form>
                        </div>
                        <div class="btn-group pull-right" style="padding-right:10px !important">
                          <form name="filter-product" method="GET" action="/admin/products/admin" style="margin:0">
                            <select name="category" id="selectCategory" onChange="this.form.submit();">
                            	<option value="">Chọn danh mục</option>
                                	<?php
                                        $categories = Category::model()->findAll('is_submenu = 2');
                                        if($categories){
                                            foreach($categories as $category) {?>
                                                <option <?php if($category->category_id == $categoryId) echo 'selected=selected';?> value="<?php echo $category->category_id;?>"><?php echo $category->title;?></option>
                                            <?php }
                                        }
                                        ?>
                            </select>
                            </form>
                        </div>
                    </div>
                    <?php if(Yii::app()->user->hasFlash('message')):?>
                        <div class="alert alert-success">
                            <?php echo Yii::app()->user->getFlash('message'); ?>
                        </div>
                    <?php endif; ?>
                    <form id="frm-product" action="/admin/products/saveorder" method="post" class="horizontal-form">
                    <table class="table table-striped table-bordered table-hover" id="sample_1">
                        <thead>
                        <tr>
                            <th style="width:8px;"><input type="checkbox" class="group-checkable"
                                                          data-set="#sample_1 .checkboxes"/></th>
                            <th>Tên SP</th>
                            <th>Hình ảnh</th>
                            <th>K.Thước(cm)</th>
                            <th>T.Lượng(gram)</th>
                            <th>Giá cũ($)</th>
                            <th>Giá mới($)</th>
                            <th width="100">Set home</th>
                            <th width="120">Sắp xếp <a href="javascript:void(0);"><i class="icon-save"></i></a></th>
                            <th></th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        if(!empty($model)) {
                            foreach($model as $index=>$product) {?>
                                <tr class="<?php if($index/2) { echo 'odd';} else { echo 'even';}?> gradeX">
                                    <td><input type="checkbox" class="checkboxes" value="1"/></td>
                                    <td><?php echo $product->title;?></td>
                                    <td>
                                        <a class="fancybox-button" data-rel="fancybox-button" title="Photo" href="/data/upload/products/<?php echo isset($product->shopImages[count($product->shopImages)-1]) ? $product->shopImages[count($product->shopImages)-1]->filename : 'no_image.jpg'?>">
                                            <div class="zoom">
                                                <img src="/data/upload/products/<?php echo isset($product->shopImages[count($product->shopImages)-1]) ? $product->shopImages[count($product->shopImages)-1]->filename : 'no_image.jpg'?>" alt="Photo" width="60" height="60"/>
                                                <div class="zoom-icon"></div>
                                            </div>
                                        </a>
                                    </td>
                                    <td><?php echo $product->size;?></td>
                                    <td><?php echo $product->weight;?></td>
                                    <td><?php echo $product->price;?>.00</td>
                                    <td><?php echo $product->new_price;?>.00</td>
                                    <td><input onclick="window.location.href='/admin/products/sethome/id/<?php echo $product->product_id?>/show/<?php echo $product->showhome;?>'" type="checkbox" class="checkboxes" value="<?php echo $product->showhome;?>" <?php echo ($product->showhome)? 'checked':'';?>/></td>
                                    <td>
                                        <a class="btn grey mini" href="javascript:void(0)"><i class="icon-circle-arrow-down" rel="<?php echo $product->product_id?>-<?php echo @$model[$index+1]->product_id?>"></i></a>
                                        <a class="btn grey mini" href="javascript:void(0)"><i class="icon-circle-arrow-up" rel="<?php echo $product->product_id?>-<?php echo @$model[$index-1]->product_id?>"></i></a>
                                        <input style="width:30px" name="order[]" id="order<?php echo $product->product_id?>" type="text" value="<?php echo $product->order?>">
                                        <input name="id[]" type="hidden" value="<?php echo $product->product_id?>">
                                    </td>
                                    <td>
                                        <a class="btn green mini" href="/admin/products/update/id/<?php echo $product->product_id?>"><i class="icon-pencil icon-white"></i></a>
                                        <a class="btn red mini" href="/admin/products/delete/id/<?php echo $product->product_id?>"><i class=" icon-remove icon-white"></i></a>
                                    </td>
                                </tr>
                        <?php }
                        }
                        ?>

                        </tbody>
                    </table>
                    <?php if(count($model) > 0) {?>
                        <div class="row-fluid">
                            <div class="span6">
                                <!--<div class="dataTables_info" id="sample_1_info">Hiển thị 1 đến 2 của 2 kết quả</div>-->
                                <div class="dataTables_info" id="sample_1_info">Hiển thị <?php echo $pages->getCurrentPage()* $page_size +1;?> đến <?php echo ($item_count >= (($pages->getCurrentPage()+1) * $page_size))?($pages->getCurrentPage()+1) * $page_size : $item_count;?> của <?php echo $item_count?> kết quả</div>
                            </div>
                            <div class="span6">
                                <div class="dataTables_paginate paging_bootstrap pagination">
                                    <?php
                                    // the pagination widget with some options to mess
                                    $this->widget('MyLinkPager', array(
                                        'currentPage' => $pages->getCurrentPage(),
                                        'itemCount' => $item_count,
                                        'pageSize' => $page_size,
                                        'maxButtonCount' => 5,
                                        'header' => '',
                                        'htmlOptions' => array('class' => 'pages'),
                                    ));
                                    ?>
                                </div>
                            </div>
                        </div>
                    <?php }?>
                </div>
            </div>
            <!-- END EXAMPLE TABLE PORTLET-->
        </div>
    </div>

    <!-- END PAGE CONTENT-->
</div>
<!-- END PAGE CONTAINER-->